package com.zky.seckillzky.seckill.controller;

import com.zky.common.utils.R;
import com.zky.seckillzky.seckill.entity.UserEntity;
import com.zky.seckillzky.seckill.redis.RedisService;
import com.zky.seckillzky.seckill.redis.UserKey;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("toredis/get")
public class RedisDemoController {

    @Autowired
    private RedisService redisService;

    @Autowired
    RedissonClient  redissonClient;


    /**
     * 测试redis set  get 方法
     */

    @RequestMapping("/redis/set")
    public R set(){
        UserEntity userEntity = new UserEntity();
        userEntity.setUserId((long)1);
        userEntity.setUsername("zhangsan");
        //KeyPrefix prefix(前缀), String key(key值),  T value
        redisService.set(UserKey.getById,""+1,userEntity);
        Map<String, String> map = new HashMap<>();
        map.put("123","123");
        return R.ok().put("success","redis存值成功");


    }

    @RequestMapping("/redis/get")
    public R get(){
        UserEntity userEntity = redisService.get(UserKey.getById, "" + 1, UserEntity.class);
        System.out.println(userEntity);
        return R.ok().put("success",userEntity);
    }




}
